#ifndef CQUADTREE_H
#define CQUADTREE_H

#include "my_utilities/mymath.h"
#include "CQuadTreePosItem.h"
#include "CQuadTreeNode.h"

#include <SFML/Graphics.hpp>

class CQuadTreePosItem;

/* Wrapper class for QuadNode; contains root/head node */
class CQuadTree
{
    public:
        CQuadTree(CRect r, int maxI); //ctor

        //inserts item into quad tree
        void Insert(CQuadTreePosItem* item);

//        //insets item into quad tree
//        void Insert(CRigidBody* par, Vec2f* ps);

        /* Query Methods */
        //gets list of items containing this point
        void QueryItems(const Vec2f& point, vector<CQuadTreePosItem* >& itemsFound);

        //gets list of items intersecting rect
        void QueryItems(const CRect& r,  vector<CQuadTreePosItem* >& itemsFound);

        //DEBUG/Dave
        void DebugQueryItems(const Vec2f& point, vector<CQuadTreePosItem* >& itemsFound, Vec2f& identifier, unsigned int& debugDepth);
        void DebugQueryItemsInParent(const Vec2f& point, vector<CQuadTreePosItem* >& itemsFound, Vec2f& identifier, unsigned int& debugDepth);
        
        //DEBUG/Dave
        void DebugPrintItems();
        
        //gets list of all items in this node
        void GetAllItems(vector<CQuadTreePosItem*>& itemsFound);

        /* ----------- */
        void Render(sf::RenderWindow& App)
        {
            headNode_.Render(App);
        }
        //getters
        CRect& GetRect() const;

    private:
        CQuadTreeNode headNode_; //root of tree
        CRect worldRect_;           //world rectangle. map size
        unsigned int maxItems_;              //max items for any node


};


#endif // CQUADTREE_H
